/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.mail.controller;

import com.google.appengine.repackaged.org.apache.commons.httpclient.URI;
import com.google.appengine.repackaged.org.apache.commons.httpclient.URIException;
import com.sun.mail.pop3.POP3SSLStore;
import java.io.*;
import java.util.*;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.search.FlagTerm;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;

import queenb.net.entitybean.M575;
import queenb.web.controller.QueenbController;
import queenb.web.mail.inteface.M575Inf;
import queenb.web.mail.store.M575Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;
import org.richfaces.model.UploadItem;
import org.richfaces.event.UploadEvent;
import queenb.net.entitybean.*;
import queenb.web.crm.controller.CustomerExpand;
import queenb.web.crm.controller.V030controller;
import queenb.web.crm.store.CustomerStore;
import queenb.web.crm.store.M250Store;
import queenb.web.store.*;
import queenb.web.util.*;

/**
 *
 * @author Nguyen Hung
 */
public class M575Controller extends QueenbController {
    
    private ComboboxUtil comboxUtil = new ComboboxUtil();
    private int fb050;
    private M575Inf m575Inf;
    private int pm575;
    private int ff150;
    private String mv576;
    private String mv577;
    private String mv578;
    private String mv579;
    private Date md580 = new Date();
    private int mn581;
    private int fh000;
    private int fh200;
    private int fq100;
    private String fm525 = "A";
    private String mv276 = "TO";
    private String mv277 = "M";
    private String hoten;
    private String title;
    private String html;
    private String text;
    private int renderMail = 0;
    private Date sendtime;
    private String reload;
    private static int intreload;
    private List<M575> listToFromMail;
    private List<M575> listToFromMailEx;
    private String loginGmailYahoo;
    private String passwordGmailYahoo;
    private M575Store m575Store = new M575Store();
    private Map<Integer, String> map = new HashMap<Integer, String>();
    private List<Map.Entry<Integer, String>> listSendMail;
    private List<ItemMail> listItemMail = new ArrayList<ItemMail>();
    private String fromMail;
    private String toMail;
    private String dateSend;
    private String titleMail;
    private String content;
    private List<ItemMail> listitem = new ArrayList<ItemMail>();
    private String colorchose = "";
    private String stylefrommail = "none";
    //send email 
    private static ArrayList<File> files = new ArrayList<File>();
    private String subjectMail;
    private String contentMail;
    private static final String SMTP_HOST_NAME = "smtp.gmail.com";
    private static final int SMTP_HOST_PORT = 465;
    private String SMTP_AUTH_USER = "";
    private String SMTP_AUTH_PWD = "";
    private String methodSend = "TO";
    private String listInfo = "";
    private String listInfoTo = "";
    private List<MailItem> listMail = new ArrayList<MailItem>();
    private String s = "";
    private Boolean chkMess = false;
    private Boolean chkMessS = false;
    private String filetemp;
    private String mailBox = "HỘP THƯ ĐẾN";
    // sendEmail for Email
    private int idcus;
    private String emailcus;
    private String typecus;
    private Boolean senper = false;
    private String pageRequest;
    private String check = "E";
    private Boolean checksendmail = false;
    private String sttTitle = "I";
    private List<SelectItem> listcomboM200;
    private List<SelectItem> listcomboQ000;
    private String valuemailtemp;
    private M200Store m200Store = new M200Store();
    private M650Store m650Store = new M650Store();
    private int pm200;
    private int stephide;// phan biet trang de reload
    private long timezone;
    private String mailsend = "";
    private int mailsendId;
    private String mailsendpass;
    private List<SelectItem> listcomboM250;
    private Boolean checkN850 = false;
    private int fm575repo;
    private int fm575list;
    private List<M575> listmailrepo;
    private int fq100repo;
    
    public M575Controller() {
        //demo auto mail

        getKapiMenu().setAdmin(false);
        Object objAction = getRequest().getParameter("action");
        System.out.println("------------action-----------" + objAction);
        Object objpage = getRequest().getParameter("page");
        Object sesspage = SessionProvider.getSessionMapValue("pageaction");
        if (sesspage != null && objpage == null) {
            objpage = sesspage;
            pageRequest = objpage.toString();
        } else if (objpage != null) {
            SessionProvider.setSessionMapValue("pageaction", objpage);
            pageRequest = objpage.toString();
        }

        //listToFromMail = getListM275(mv276, 0);
        listInfo = "";
        listMail.clear();
        List<N100> listKH = new ArrayList<N100>();
        List<B630> listCSKH = new ArrayList<B630>();
        if (objpage != null) {
            s = objpage.toString();
            if (s.equals("customer4tour")) {
                Object listselect = SessionProvider.getSessionMapValue("listSelected");
                if (listselect != null) {
                    try {
                        listKH = (List<N100>) listselect;
                    } catch (Exception e) {
                        listKH = new ArrayList<N100>();
                    }
                } else {
                    listKH = new ArrayList<N100>();
                }
                //listKH = V030controller.listSelected;
                SessionProvider.setSessionMapValue("cus4tour", 1);
            } else if (s.equals("customerexpand")) {
                Object listselect = SessionProvider.getSessionMapValue("listSelectedEx");
                if (listselect != null) {
                    try {
                        listKH = (List<N100>) listselect;
                    } catch (Exception e) {
                        listKH = new ArrayList<N100>();
                    }
                } else {
                    listKH = new ArrayList<N100>();
                }
                //listKH = CustomerExpand.listSelected;
            } //workChargeCM
            else if (s.equals("workChargeCM")) {
                Object listselect = SessionProvider.getSessionMapValue("listSelectedB630CM");
                if (listselect != null) {
                    try {
                        listCSKH = (List<B630>) listselect;
                    } catch (Exception e) {
                        listCSKH = new ArrayList<B630>();
                    }
                } else {
                    listCSKH = new ArrayList<B630>();
                }
            } else if (s.equals("employee")) {
                // goi lít All
                List<N100> listN100Emp = getListAllEmployeeSendSMS_Email();
                System.out.println("------------- LIST-----------" + listN100Emp.size());
                if (listN100Emp != null) {
                    try {
                        listKH = (List<N100>) listN100Emp;
                    } catch (Exception e) {
                        listKH = new ArrayList<N100>();
                    }
                } else {
                    listKH = new ArrayList<N100>();
                }
            } // danh shach nhan vien cong ty 
            else if (s.equals("listEmployee")) {
                
                Object objectStep = getRequest().getParameter("step");
                
                if (objectStep != null) {
                    stephide = Util.parseInt(objectStep);
                }
                Object objectFk100 = getRequest().getParameter("fk100reload");
                if (objectFk100 != null) {
                    fb050 = Util.parseInt(objectFk100);
                }
                Object listselect = SessionProvider.getSessionMapValue("listPersonalDSVN");
                if (listselect != null) {
                    try {
                        listKH = (List<N100>) listselect;
                    } catch (Exception e) {
                        listKH = new ArrayList<N100>();
                    }
                } else {
                    listKH = new ArrayList<N100>();
                }
            } // danh sahc nguoi dai dien cua cong ty
            else if (s.equals("listPersonal")) {
                
                Object objectStep = getRequest().getParameter("step");
                
                if (objectStep != null) {
                    stephide = Util.parseInt(objectStep);
                }
                Object objectFk100 = getRequest().getParameter("fk100reload");
                if (objectFk100 != null) {
                    fb050 = Util.parseInt(objectFk100);
                }
                Object listselect = SessionProvider.getSessionMapValue("listPersonalDSDD");
                if (listselect != null) {
                    try {
                        listKH = (List<N100>) listselect;
                    } catch (Exception e) {
                        listKH = new ArrayList<N100>();
                    }
                } else {
                    listKH = new ArrayList<N100>();
                }
            } else if (s.equals("workChargeCOM")) {
                Object listselect = SessionProvider.getSessionMapValue("listSelectedB630COM");
                if (listselect != null) {
                    try {
                        listCSKH = (List<B630>) listselect;
                    } catch (Exception e) {
                        listCSKH = new ArrayList<B630>();
                    }
                } else {
                    listCSKH = new ArrayList<B630>();
                }
            } else if (s.equals("companyMail")) {
                Object objectStep1 = getRequest().getParameter("step");
                
                if (objectStep1 != null) {
                    stephide = Util.parseInt(objectStep1);
                }
                Object listselect = getListAllCompanySendSMS_Email();
                if (listselect != null) {
                    try {
                        listKH = (List<N100>) listselect;
                    } catch (Exception e) {
                        listKH = new ArrayList<N100>();
                    }
                } else {
                    listKH = new ArrayList<N100>();
                }
            }
        }
        
        if (s.equals("workChargeCM") || s.equals("workChargeCOM")) {
            for (int i = 0; i < listCSKH.size(); i++) {
                B630 cus = listCSKH.get(i);
                if (cus.getNv105() != null && cus.getNv105() != "" && cus.getNv105().contains("@")) {
                    MailItem mail = new MailItem(cus.getFq100(), cus.getHoten(), cus.getNv105(), "", "Kính gửi quý khách: ", "");
                    listMail.add(mail);
                    listInfo += listCSKH.get(i).getNv105() + ";  ";
                }
                
            }
        } else if (s.equals("customer4tour") || s.equals("customerexpand")) {
            for (int i = 0; i < listKH.size(); i++) {
                N100 cus = listKH.get(i);
                if (cus.getNv105() != null && cus.getNv105() != "" && cus.getNv105().contains("@")) {
                    MailItem mail = new MailItem(cus.pn100, cus.getHoten(), cus.getNv105(), "", cus.getPronouns(), "");
                    listMail.add(mail);
                    listInfo += listKH.get(i).getNv105() + ";  ";
                }
                
            }
        } else if (s.equals("listEmployee") || s.equals("listPersonal")) {
            for (int i = 0; i < listKH.size(); i++) {
                N100 cus = listKH.get(i);
                if (cus.getNv120() != null && cus.getNv120() != "" && cus.getNv120().contains("@")) {
                    MailItem mail = new MailItem(cus.pn100, cus.getHoten(), cus.getNv120(), "", cus.getPronouns(), "");
                    listMail.add(mail);
                    listInfo += listKH.get(i).getNv120() + ";  ";
                }
                
            }
        } else if (s.equals("employee")) {
            for (int i = 0; i < listKH.size(); i++) {
                N100 cus = listKH.get(i);
                if (cus.getNv105() != null && cus.getNv105() != "" && cus.getNv105().contains("@")) {
                    MailItem mail = new MailItem(cus.pn100, cus.getHoten(), cus.getNv105(), "", cus.getPronouns(), "");
                    listMail.add(mail);
                    listInfo += listKH.get(i).getNv105() + ";  ";
                }
                
            }
        } else if (s.equals("companyMail")) {
            for (int i = 0; i < listKH.size(); i++) {
                N100 cus = listKH.get(i);
                if (cus.getNv967() != null && cus.getNv967() != "" && cus.getNv967().contains("@")) {
                    MailItem mail = new MailItem(cus.pn100, cus.getHoten(), cus.getNv967(), "", cus.getPronouns(), "");
                    listMail.add(mail);
                    listInfo += listKH.get(i).getNv967() + ";  ";
                }
                
            }
        }
        
        
        
        getKapiMenu().setMainmenu1("m191"); // Hien thi Menu nao dc chon
        System.out.println("========================================listMail" + listInfo);
        if (objAction != null) {
            if (objAction.equals("come_person")) {
                Object objKey = getRequest().getParameter("key");
                getMap().size();
                System.out.println("SL truoc: " + getMap().size());
                map.remove(Integer.parseInt(objKey.toString()));
                listSendMail = new ArrayList(map.entrySet());
                System.out.println("SL sau: " + map.size());
                SessionProvider.putSession("mapEmail", map);
                if (listSendMail != null) {
                    stylefrommail = "block";
                } else {
                    stylefrommail = "none";
                }
                System.out.println("objkey-----------------" + objKey);
            }
            
            if (objAction.equals("inbox")) {
                System.out.println("D:- Danh sach hop thu noi bo den");
                Object objInbox = getRequest().getParameter("mv276");
                mailBox = "HỘP THƯ ĐẾN";
                sttTitle = "I";
                if (objInbox != null) {
                    this.mv276 = objInbox.toString();
                    listToFromMail = getListM275(mv276, 0);
                }
            }
            if (objAction.equals("outbox")) {
                System.out.println("D:- Danh sach thu noi bo da gui");
                Object objOutbox = getRequest().getParameter("mv276");
                mailBox = "THƯ ĐÃ GỬI";
                sttTitle = "O";
                if (objOutbox != null) {
                    this.mv276 = objOutbox.toString();
                    listToFromMail = getListM275(mv276, 0);
                }
            }
            if (objAction.equals("delete")) {
                System.out.println("D:- Danh sach thu noi bo da xoa");
                Object objOutbox = getRequest().getParameter("fm525");
                mailBox = "THƯ ĐÃ XÓA";
                sttTitle = "D";
                if (objOutbox != null) {
                    this.fm525 = objOutbox.toString();
                    System.out.println("D:- danh sach mail bị xoa ! getListM275(mv276, 0, fm525): " + mv276 + "," + 0 + " , " + fm525);
                    //listToFromMail = getListM275(mv276, 0, fm525);
                }
            }
            if (objAction.equals("maildetail")) {
                Object pnFM575 = getRequest().getParameter("pm575");
                Object objMv276 = getRequest().getParameter("mv276");
                if (objMv276 != null) {
                    System.out.println("-----------------mv272----" + objMv276);
                    this.mv276 = objMv276.toString();
                    listToFromMail = getListM275(mv276, 0);
                }
                colorchose = "#4A5763";
                if (pnFM575 != null) {
                    this.pm575 = Integer.parseInt(pnFM575.toString());
                    List<M575> listDetail = getListM275(mv276, pm575);
                    renderMail = 1;
                    if (listDetail != null) {
                        Iterator iterator = listDetail.iterator();
                        while (iterator.hasNext()) {
                            M575 m575 = (M575) iterator.next();
                            this.pm575 = m575.getPm575();
                            System.out.println("-text--------------------->" + m575.getText());
                            this.mv578 = m575.getText();
                            this.hoten = m575.getHoten();
                            this.title = m575.getTitle();
                            this.sendtime = m575.getSendtime();
                            this.fq100 = m575.getFq100();
                        }
                    }
                }
                
            }
            if (objAction.equals("reply")) {
                Object objQ100 = getRequest().getParameter("fq100");
                this.fq100 = Integer.parseInt(objQ100.toString());
                
                Object objTitle = getRequest().getParameter("title");
                this.mv576 = objTitle.toString();
                System.out.println("----------mv576-------------" + mv576);
            }
            if (objAction.equals("clear")) {
                System.out.println("D:-- clear mapgetN");
                map.clear();
                SessionProvider.putSession("mapEmail", null);
            }
            
        }

        // getparamater for send mail 
//        this.senper=false;
        Q100Store storeQ100 = new Q100Store();
        Object objid = getRequest().getParameter("idx");
        Object objmail = getRequest().getParameter("mailx");
        Object objtype = getRequest().getParameter("typex");
        if (objid != null && objmail != null && objtype != null) {
            try {
                this.idcus = Integer.parseInt(objid.toString());
                this.emailcus = objmail.toString().trim();
                this.typecus = objtype.toString().trim();
                System.out.println("D:- sendmail nhan vien : id:= " + objid.toString() + ", email:= " + objmail.toString());
                if (idcus == -1) {
                    System.out.println("D:- Khong xac dinh duoc id :=" + idcus);
                    idcus = storeQ100.getIdByUserLogin(emailcus);
                    SessionProvider.setSessionMapValue("idcus", idcus);
                    SessionProvider.setSessionMapValue("inout", "I");
                    System.out.println("D:- set id:=" + idcus + " of email: " + emailcus);
                } else {
                    System.out.println("D:- Xac dinh duoc id : " + objid.toString());
                    SessionProvider.setSessionMapValue("idcus", objid);
                    SessionProvider.setSessionMapValue("inout", "E");
                }
                
                SessionProvider.setSessionMapValue("emailcus", objmail);
                SessionProvider.setSessionMapValue("typecus", objtype);
                this.senper = true;
            } catch (Exception e) {
                System.out.println("D:-- sendmail to person: " + e.getMessage());
                this.idcus = Integer.parseInt("0");
                this.emailcus = "";
                this.typecus = "";
                this.senper = false;
            }
        } else {
            try {
                this.idcus = Integer.parseInt(SessionProvider.getSessionMapValue("idcus").toString());
                this.emailcus = SessionProvider.getSessionMapValue("emailcus").toString();
                this.typecus = SessionProvider.getSessionMapValue("typecus").toString();
            } catch (Exception e) {
                System.out.println("D:-- sendmail to person: " + e.getMessage());
                this.idcus = Integer.parseInt("0");
                this.emailcus = "";
                this.typecus = "";
                this.senper = false;
            }
        }
        
        Object objide = getRequest().getParameter("ide");
        Object objidq = getRequest().getParameter("idq");
        Object objstatus = getRequest().getParameter("status");
        if (objide != null && objstatus != null) {
            try {
                System.out.println("D:- chuyen trang thai email: id:= " + objide + "Status:= " + objstatus.toString() + " objidq : " + objidq);
                int ide = Integer.parseInt(objide.toString());
                int idq = 0;
                if (objidq != null) {
                    idq = Integer.parseInt(objidq.toString());
                }
                String status = objstatus.toString();
                m575Store.updateM275OneColumn(null, "M275", "FM525", status, "PM275", ide, getLogin().getUserName());
                if (status.equals("D")) {
                    if (objidq != null) {
                        System.out.println("D:- Delete mail !");
                        m575Store.deleteM275(ide, idq, getLogin().getUserName());
                    }
                    
                } else if (status.equals("R")) {
                    if (objidq != null) {
                        System.out.println("D:- restore mail !");
                        m575Store.restoreM275(ide, idq, getLogin().getUserName());
                    }
                    
                }
            } catch (Exception e) {
                System.out.println("D:- Error from chuyen trang thai Email: " + e.getMessage());
            }
        }
        
        Object objidm = getRequest().getParameter("idm");
        if (objidm != null) {
            try {
                int id = Integer.parseInt(objidm.toString());
                List<M200> list = m200Store.getListM200All(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getId(), getLogin().getUserName());
                if (list.size() > 0) {
                    for (int i = 0; i < list.size(); i++) {
                        if (list.get(i).getPm200() == id) {
                            this.valuemailtemp = (list.get(i).getMv202());
                            break;
                        }
                    }
                }
            } catch (Exception e) {
                System.out.println("D:- Error from chuyen trang thai Email: " + e.getMessage());
            }
        }

        //ma tour de gui mail
        Object objFv050 = getRequest().getParameter("v050mail");
        if (objFv050 != null) {
            System.out.println("code tour for sendmail:" + objFv050);
            SessionProvider.setSessionMapValue("v050mail", objFv050);
        }

        // thong tin reply actionforward
        Object objforward = getRequest().getParameter("actionforward");
        if (objforward != null) {
            try {
                fm575repo = Integer.parseInt(objforward.toString());
                getM575FoByid(fm575repo);
                SessionProvider.setSessionMapValue("fm575repo", fm575repo);
            } catch (Exception e) {
                System.out.println("D:- error from objforward: " + e.getMessage());
            }
        }
        // thong tin forward actionreply
        Object objreply = getRequest().getParameter("actionreply");
        if (objreply != null) {
            try {
                fm575repo = Integer.parseInt(objreply.toString());
                getM575ReByid(fm575repo);
                SessionProvider.setSessionMapValue("fm575repo", fm575repo);
            } catch (Exception e) {
                System.out.println("D:- error from objreply: " + e.getMessage());
            }
        }

        // danh sach mail reply - forward

        Object objrepo = getRequest().getParameter("repo");
        if (objrepo != null) {
            System.out.println("repo : " + objrepo);
            try {
                fm575list = Integer.parseInt(objrepo.toString());
                System.out.println("fm575list : " + fm575list);
            } catch (Exception e) {
                System.out.println("D:- error from objrepo: " + e.getMessage());
            }
        }
        
    }
    
    private void getM575ReByid(int id) {
        try {
            M575Store store = new M575Store();
            System.out.println("m575Store.mcurpks_listoftabm275id(" + getLogin().getModule() + " , " + getLogin().getCompanyNo() + " , " + id + " , " + getLogin().getUserName());
            List<M575> list = m575Store.mcurpks_listoftabm275id(getLogin().getModule(), getLogin().getCompanyNo(), id, getLogin().getUserName());
            if (list != null) {
                System.out.println("list: " + list.size());
                for (M575 m575 : list) {
                    subjectMail = "Re: " + m575.getTitle();
                    contentMail = m575.getText();
                    listInfoTo = m575.getSmail();
                    setFq100repo(m575.getFq100());
                    mv577 = "R";
                    System.out.println("subjectMail: " + subjectMail + "fq100: " + fq100repo + "MV577: " + mv577);
                    SessionProvider.setSessionMapValue("fq100repo", fq100repo);
                    SessionProvider.setSessionMapValue("mv577repo", mv577);
                }
            }
        } catch (Exception e) {
            System.err.println("D:- error from getM575Byid: " + e.getMessage());
        }
        
    }
    
    private void getM575FoByid(int id) {
        try {
            M575Store store = new M575Store();
            System.out.println("m575Store.mcurpks_listoftabm275id(" + getLogin().getModule() + " , " + getLogin().getCompanyNo() + " , " + id + " , " + getLogin().getUserName());
            List<M575> list = m575Store.mcurpks_listoftabm275id(getLogin().getModule(), getLogin().getCompanyNo(), id, getLogin().getUserName());
            if (list != null) {
                System.out.println("list: " + list.size());
                for (M575 m575 : list) {
                    subjectMail = "FW: " + m575.getTitle();
                    contentMail = m575.getText();
                    mv577 = "F";
                    setFq100repo(m575.getFq100());
                    System.out.println("subjectMail: " + subjectMail + "fq100: " + fq100repo + "MV577: " + mv577);
                    SessionProvider.setSessionMapValue("fq100repo", fq100repo);
                    SessionProvider.setSessionMapValue("mv577repo", mv577);
                }
            }
        } catch (Exception e) {
            System.err.println("D:- error from getM575Byid: " + e.getMessage());
        }
        
    }
    
    public void getM250ReviceById(int pm250) {
        try {
            M250Store m250Store = new M250Store();
            List<M250> lst = m250Store.getListM250(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getFn850(), getLogin().getUserName());
            if (lst != null && lst.size() > 0) {
                System.out.println("D:- list getM250ReviceById: " + lst.size());
                for (M250 m250 : lst) {
                    if (m250.getPm250() == pm250) {
                        this.mailsend = m250.getMv251();
                        this.mailsendpass = m250.getMv255();
                    }
                }
            } else {
                System.out.println("D:- list getM250ReviceById: null");
            }
        } catch (Exception e) {
            System.err.println("D: erro from getM250ReviceById: " + e.getMessage());
        }
        
        
    }
    
    public void sendMail(String username, String pass, String email, String subject, String content) {
        String SMTP_AUTH_USER = "";
        String SMTP_AUTH_PWD = "";
        String SMTP_HOST_NAME = "smtp.gmail.com";
        int SMTP_HOST_PORT = 465;
        try {
            SMTP_AUTH_USER = username;//your email address
            SMTP_AUTH_PWD = pass;//your password
            Properties props = new Properties();
            
            props.put("mail.transport.protocol", "smtps");
            props.put("mail.smtp.host", SMTP_HOST_NAME);
            props.put("mail.smtps.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtps.from", "kakaka@machine");
            
            Session mailSession = Session.getInstance(props);
            mailSession.setDebug(true);
            Transport transport = mailSession.getTransport();
            System.out.append("---------------1\n");
            
            MimeMessage message = new MimeMessage(mailSession);
            message.setSubject(subject, "utf-8");
            
            MimeMultipart multipart = new MimeMultipart("mixed");
            message.setContent(multipart);
            
            message.addRecipient(Message.RecipientType.BCC, new InternetAddress(email));
            
            transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
            System.out.append("---------------2\n");
            
            MimeBodyPart textMBCC = new MimeBodyPart();
            textMBCC.setContent(content, "text/html; charset=utf-8");
            multipart.addBodyPart(textMBCC);
            Address[] st = new Address[1];
            st[0] = new InternetAddress(email);
            transport.sendMessage(message, st);
            
            transport.close();
            
        } catch (Exception e) {
            System.out.println("--D: Error from sendmail: " + e.getMessage());
            chkMess = true;
        }
    }

    // list lay emial va mobi KHC|CN
    public List<N100> getListAllCompanySendSMS_Email() {
        try {
            
            EmployeeStore employeeStore = new EmployeeStore();
//            if(SessionProvider.getSessionMapValue("IDSENDSMSMAIL")!=null){
//              fn850 = Util.parseInt(SessionProvider.getSessionMapValue("IDSENDSMSMAIL"))   ;
//            }else{
//                 fn850 = Util.parseInt(SessionProvider.getSessionMapValue("groupID"))   ; 
//            }

            List<N100> listAll = employeeStore.ncurpks_listoftabn100lcon(getLogin().getModule(), getLogin().getCompanyNo(), 2, getLogin().getUserName());
            System.out.println("-------------LIST-----------------" + listAll.size());
            return listAll;
        } catch (Exception e) {
            return null;
        }
    }
    
    public void getQ000SendById(int pq000) {
        Q000Store q000Store = new Q000Store();
        List<Q000> lst = q000Store.getListQ000(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getId(), getLogin().getUserName());
        if (lst != null) {
            System.out.println("D:- list getListAllQ000ByIDofMyprofile: " + lst.size());
        } else {
            System.out.println("D:- list getListAllQ000ByIDofMyprofile: null");
        }
        for (Q000 q000 : lst) {
            if (q000.getPQ000() == pq000) {
                this.mailsend = q000.getQV001();
                this.mailsendpass = q000.getQV002();
            }
        }
    }

    // List All Eployee
    public List<N100> getListAllEmployeeSendSMS_Email() {
        try {
            int fn850 = 0;
            EmployeeStore employeeStore = new EmployeeStore();
            if (SessionProvider.getSessionMapValue("IDSENDSMSMAIL") != null) {
                fn850 = Util.parseInt(SessionProvider.getSessionMapValue("IDSENDSMSMAIL"));
            } else {
                fn850 = Util.parseInt(SessionProvider.getSessionMapValue("groupID"));
            }
            
            List<N100> listAll = employeeStore.getAllListTabN100All(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, fn850, 0, null, 0, 1000, 0, 0, getLogin().getUserName());
            return listAll;
        } catch (Exception e) {
            return null;
        }
    }
    
    public void listener(UploadEvent event) throws Exception {
        
        UploadItem item = event.getUploadItem();
        
        String path = item.getFile().getPath();
        
        int myIndex = 0;
        int l = path.length();
        for (int i = path.length() - 1; i > 0; i--) {
            if (path.charAt(i) == '\\') {
                myIndex = i;
                break;
            }
        }
        
        String temp = path.substring(myIndex + 1, l);
        String path2 = path.replaceAll(temp, item.getFileName());
        
        if ((new File(path2)).exists()) {
            (new File(path2)).delete();
        }
        
        File file = new File(path);
        file.renameTo(new File(path2));
        File file2 = new File(path2);
        files.add(file2);
        System.out.println(" DANH SACH TAP TIN DINH KEM!");
        for (File filetemp : files) {
            System.out.println("-- " + filetemp.getName() + "--- " + filetemp.getPath());
        }
    }
    
    public void changen850(ActionEvent ac) {
        System.out.println("D:---change change4ldv " + checkN850);
        if (checkN850) {
            SessionProvider.setSessionMapValue("checkN850", 1);
        } else {
            SessionProvider.setSessionMapValue("checkN850", 0);
        }
        
        
        
    }
    
    public void sendEmail() {
        try {
            //automail();
            System.out.println("D:- mailsend id: " + mailsendId);
            if (getCheckN850()) {
                getM250ReviceById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            } else {
                getQ000SendById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            }

            // senmail authentication yahoo sever

            // check code tour
            Object objfv050 = SessionProvider.getSessionMapValue("v050mail");
            String mv582 = "";
            String mv582str = "";
            Object objcus4tour = SessionProvider.getSessionMapValue("cus4tour");
            if (objfv050 != null) {
                System.out.println("lay code tour to sendmail !: " + objfv050);
                try {
                    
                    if (objcus4tour != null) {
                        
                        int a = Integer.parseInt(objfv050.toString().trim());
                        V050Store v050store = new V050Store();
                        System.out.println("v050store.listV050All(" + getLogin().getModule() + " , " + getLogin().getCompanyNo() + " , " + a + " , " + null + " , " + getLogin().getUserName());
                        List<V050> list = v050store.listV050All(getLogin().getModule(), getLogin().getCompanyNo(), a, null, getLogin().getUserName());
                        System.out.println("list: " + list.size());
                        if (list != null && list.size() > 0) {
                            for (V050 v050 : list) {
                                mv582 = "";
                                mv582str = "";
                                mv582str = "[" + v050.getVv051() + "] - " + " ";
                                mv582 = v050.getVv051();
                            }
                        }
                    }
                    
                } catch (Exception e) {
                    System.err.println("error from objfv050: " + e.getMessage());
                }
            }
            
            if (SMTP_AUTH_USER.contains("@yahoo.com") || SMTP_AUTH_USER.contains("@ymail.com")) {
                String host, port;
                Properties props = System.getProperties();
                Session l_session = null;
                host = "smtp.mail.yahoo.com";
                port = "587";
                
                props.put("mail.smtp.host", host);
                props.put("mail.smtp.auth", "true");
                props.put("mail.debug", "false");
                props.put("mail.smtp.port", port);
                props.put("mail.smtp.starttls.enable", "true");
                
                l_session = Session.getInstance(props,
                        new javax.mail.Authenticator() {
                            
                            protected PasswordAuthentication getPasswordAuthentication() {
                                return new PasswordAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
                            }
                        });
                
                l_session.setDebug(true); // Enable the debug mode

                MimeMessage message = new MimeMessage(l_session);
                String emailid = SMTP_AUTH_USER;
                message.setFrom(new InternetAddress(emailid));
                
                int cout = 0;
                String[] tempd = listInfoTo.split(",");
                if (listInfoTo != "") {
                    for (int i = 0; i < tempd.length; i++) {
                        if (tempd[i] != "" && tempd[i].contains("@")) {
                            cout++;
                            message.addRecipient(Message.RecipientType.TO, new InternetAddress(tempd[i].trim()));
                        }
                        
                    }
                }
                // senmail CC to list 
                Address[] addr = null;
                if (listInfoTo != "") {
                    addr = new Address[cout];
                }
                
                if (listInfoTo != "") {
                    for (int i = 0; i < cout; i++) {
                        addr[i] = new InternetAddress(tempd[i]);
                    }
                }
                MimeMultipart multipart = new MimeMultipart("mixed");
                List<AttachItem> listAttach = new ArrayList<AttachItem>();
                for (int i = 0; i < files.size(); i++) {
                    MimeBodyPart messageBodyPart1 = new MimeBodyPart();
                    messageBodyPart1.attachFile(files.get(i).getPath());
                    System.out.println("D:-- attachFile: " + files.get(i).getPath());
                    
                    multipart.addBodyPart(messageBodyPart1);
                    try {
                        InputStream is = new FileInputStream(files.get(i));
                        // save attach in sever
                        String url = files.get(i).getName().replaceAll(" ", "");
                        String urlmd5 = Util.createGUID() + "_" + files.get(i).getName().replaceAll(" ", "");
                        File f = new File(ResourcesProvider.getUploadMail() + urlmd5);
                        FileOutputStream fos = new FileOutputStream(f);
                        byte[] buf = new byte[4096];
                        int bytesRead;
                        while ((bytesRead = is.read(buf)) != -1) {
                            fos.write(buf, 0, bytesRead);
                        }
                        fos.close();
                        AttachItem att = new AttachItem(url, urlmd5);
                        listAttach.add(att);
                    } catch (Exception e) {
                        continue;
                    }
                    
                }
                message.setContent(multipart);
                message.setSubject(mv582str + subjectMail, "utf-8");
                message.setContent(contentMail, "text/html; charset=utf-8");
                Transport.send(message);
                System.out.println("Message Sent");
                
                
                System.out.println("m575Inf.updateM575N(" + getLogin().getModule() + " , " + getLogin().getCompanyNo() + " , " + this.getFb050() + " , " + this.getPm575() + " , " + 1 + " , " + subjectMail + " , " + this.getMv577() + " , " + "contentMail" + " , " + this.getMv579() + " , " + Util.toSQLDate(new Date()) + " , " + 0 + " , " + mv582 + " , " + "D" + " , " + mailsend + " , " + getLogin().getUserName());
                int roweffect = m575Inf.updateM575N(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), this.getPm575(), 1, mv582str + subjectMail, this.getMv577(), contentMail, this.getMv579(), Util.toSQLDate(new Date()), 0, mv582, "D", mailsend, 0, getLogin().getUserName());
                if (roweffect > 0 && listAttach != null) {
                    for (AttachItem attach : listAttach) {
                        try {
                            m650Store.updateM650(
                                    0, loginSession.getLogin().getModule(), loginSession.getLogin().getCompanyNo(), 0, 0, null, 0,
                                    "", attach.getUrl(), attach.getUrlmd5(),
                                    0,
                                    null, "M575", roweffect, 0, null, "MAIL", 7,
                                    loginSession.getLogin().getUserName());
                        } catch (Exception e) {
                            continue;
                        }
                    }
                }
                for (MailItem item : listMail) {
                    if (item.getEmailAddress() != null && item.getEmailAddress() != "" && item.getEmailAddress().contains("@")) {
                        if (objcus4tour == null) {
                            CustomerStore cusstore = new CustomerStore();
                            List<N100> list = cusstore.getListCustomerById(item.getIditem(), getLogin().getUserName());
                            if (list != null && list.size() > 0) {
                                for (N100 n100 : list) {
                                    mv582 = "";
                                    mv582str = "";
                                    mv582str = "[" + n100.getNv116() + "] - " + " ";
                                    
                                }
                            }
                        }
                        String content = "";
                        content = item.getSex() + ": " + item.getName() + "\n" + contentMail;
                        sendMailBccYAHOO(item.getIditem(), item.getEmailAddress(), mv582str + subjectMail, content, files, roweffect);
                    }
                    
                }
                
                chkMessS = true;
                files.clear();

                //sendmail gmail    
            } else {
                Properties props = new Properties();
                
                props.put("mail.transport.protocol", "smtps");
                props.put("mail.smtp.host", SMTP_HOST_NAME);
                props.put("mail.smtps.auth", "true");
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtps.from", "kakaka@machine");
                
                Session mailSession = Session.getInstance(props);
                mailSession.setDebug(true);
                Transport transport = mailSession.getTransport();
                System.out.append("---------------1\n");
                
                MimeMultipart multipart = new MimeMultipart("mixed");
                List<AttachItem> listAttach = new ArrayList<AttachItem>();
                for (int i = 0; i < files.size(); i++) {
                    MimeBodyPart messageBodyPart1 = new MimeBodyPart();
                    messageBodyPart1.attachFile(files.get(i).getPath());
                    multipart.addBodyPart(messageBodyPart1);
                    
                    try {
                        InputStream is = new FileInputStream(files.get(i));
                        // save attach in sever
                        String url = files.get(i).getName().replaceAll(" ", "");
                        String urlmd5 = Util.createGUID() + "_" + files.get(i).getName().replaceAll(" ", "");
                        File f = new File(ResourcesProvider.getUploadMail() + urlmd5);
                        FileOutputStream fos = new FileOutputStream(f);
                        byte[] buf = new byte[4096];
                        int bytesRead;
                        while ((bytesRead = is.read(buf)) != -1) {
                            fos.write(buf, 0, bytesRead);
                        }
                        fos.close();
                        AttachItem att = new AttachItem(url, urlmd5);
                        listAttach.add(att);
                    } catch (Exception e) {
                        continue;
                    }
                }
                
                MimeMessage message = new MimeMessage(mailSession);
                message.setSubject(mv582str + subjectMail, "utf-8");
                
                message.setContent(multipart);
//            for (int i = 0; i < listMail.size(); i++) {
//                if (listMail.get(i).getEmailAddress() != null && listMail.get(i).getEmailAddress() != "" && listMail.get(i).getEmailAddress().contains("@") ){
//                    message.addRecipient(Message.RecipientType.BCC, new InternetAddress(listMail.get(i).getEmailAddress()));
//                }
//            }
                int cout = 0;
                String[] tempd = listInfoTo.split(",");
                if (listInfoTo != "") {
                    for (int i = 0; i < tempd.length; i++) {
                        if (tempd[i] != "" && tempd[i].contains("@")) {
                            cout++;
                            message.addRecipient(Message.RecipientType.TO, new InternetAddress(tempd[i].trim()));
                        }
                        
                    }
                }
                
                
                transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
                System.out.append("---------------2\n");

                // senmail CC to list 
                Address[] addr = null;
                if (listInfoTo != "") {
                    addr = new Address[cout];
                }
                
                if (listInfoTo != "") {
                    for (int i = 0; i < cout; i++) {
                        addr[i] = new InternetAddress(tempd[i]);
                    }
                }

//            MimeBodyPart textMBCC = new MimeBodyPart();
//
//            
//            System.out.append("---------------3\n");
//            int checksendmail = 0;
//            for (MailItem item : listMail) {
//                if (item.getEmailAddress() != null && item.getEmailAddress() != "" && item.getEmailAddress().contains("@")) {
//                    textMBCC.setContent(item.getSex() + ": " + item.getName() + "\n" + contentMail, "text/html; charset=utf-8");
//                    multipart.addBodyPart(textMBCC);
//                    Address[] s = new Address[1];
//                    s[0] = new InternetAddress(item.getEmailAddress());
//                    transport.sendMessage(message, s);
//                    checksendmail = 1;
//                }
//
//            }
                MimeBodyPart textCC = new MimeBodyPart();
                if (addr != null && addr.length > 0) {
                    textCC.setContent(contentMail, "text/html; charset=utf-8");
                    multipart.addBodyPart(textCC);
                    transport.sendMessage(message, addr);
                }
                
                transport.close();
                
                if (listMail != null && listMail.size() > 0) {
                    
                    
                    
                    System.out.println("m575Inf.updateM575N(" + getLogin().getModule() + " , " + getLogin().getCompanyNo() + " , " + this.getFb050() + " , " + this.getPm575() + " , " + 1 + " , " + mv582str + subjectMail + " , " + this.getMv577() + " , " + "contentMail" + " , " + this.getMv579() + " , " + Util.toSQLDate(new Date()) + " , " + 0 + " , " + mv582 + " , " + "D" + " , " + mailsend + " , " + getLogin().getUserName());
                    int roweffect = m575Inf.updateM575N(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), this.getPm575(), 1, mv582str + subjectMail, this.getMv577(), contentMail, this.getMv579(), Util.toSQLDate(new Date()), 0, mv582, "D", mailsend, 0, getLogin().getUserName());
                    
                    if (roweffect > 0 && listAttach != null) {
                        for (AttachItem attach : listAttach) {
                            try {
                                m650Store.updateM650(
                                        0, loginSession.getLogin().getModule(), loginSession.getLogin().getCompanyNo(), 0, 0, null, 0,
                                        "", attach.getUrl(), attach.getUrlmd5(),
                                        0,
                                        null, "M575", roweffect, 0, null, "MAIL", 7,
                                        loginSession.getLogin().getUserName());
                            } catch (Exception e) {
                                continue;
                            }
                        }
                    }
                    
                    for (MailItem item : listMail) {
                        if (item.getEmailAddress() != null && item.getEmailAddress() != "" && item.getEmailAddress().contains("@")) {
                            if (objcus4tour == null) {
                                CustomerStore cusstore = new CustomerStore();
                                List<N100> list = cusstore.getListCustomerById(item.getIditem(), getLogin().getUserName());
                                if (list != null && list.size() > 0) {
                                    for (N100 n100 : list) {
                                        mv582 = "";
                                        mv582str = "";
                                        mv582str = "[" + n100.getNv116() + "] - " + " ";
                                        
                                    }
                                }
                            }
                            String content = "";
                            content = item.getSex() + ": " + item.getName() + "\n" + contentMail;
                            sendMailBcc(item.getIditem(), item.getEmailAddress(), mv582str + subjectMail, content, files, roweffect);
                        }
                        
                    }
                }
                
                
                chkMessS = true;
                files.clear();
//            showGlobalReport(true, getResourceString("senmailsuccessful"));
//            sendRedirect(getPageRequest()+".jsp");

            }
            
            
        } catch (Exception e) {
            System.out.println("--D: Error from sendmail: " + e.getMessage());
            chkMess = true;
//            showGlobalReport(true, getResourceString("senmailfail"));
//            sendRedirect(getPageRequest()+".jsp");
        }
        SessionProvider.setSessionMapValue("v050mail", null);
        SessionProvider.setSessionMapValue("cus4tour", null);
    }
    
    public void sendEmailrepo() {
        System.out.println("D:- sendEmailrepo id: " + mailsendId);
        try {
            //automail();
            System.out.println("D:- sendEmailrepo id: " + mailsendId);
            if (getCheckN850()) {
                getM250ReviceById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            } else {
                getQ000SendById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            }
            
            
            Properties props = new Properties();
            
            props.put("mail.transport.protocol", "smtps");
            props.put("mail.smtp.host", SMTP_HOST_NAME);
            props.put("mail.smtps.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtps.from", "kakaka@machine");
            
            Session mailSession = Session.getInstance(props);
            mailSession.setDebug(true);
            Transport transport = mailSession.getTransport();
            System.out.append("---------------1\n");
            
            MimeMultipart multipart = new MimeMultipart("mixed");
            List<AttachItem> listAttach = new ArrayList<AttachItem>();
            for (int i = 0; i < files.size(); i++) {
                MimeBodyPart messageBodyPart1 = new MimeBodyPart();
                messageBodyPart1.attachFile(files.get(i).getPath());
                multipart.addBodyPart(messageBodyPart1);
                
                try {
                    InputStream is = new FileInputStream(files.get(i));
                    // save attach in sever
                    String url = files.get(i).getName().replaceAll(" ", "");
                    String urlmd5 = Util.createGUID() + "_" + files.get(i).getName().replaceAll(" ", "");
                    File f = new File(ResourcesProvider.getUploadMail() + urlmd5);
                    FileOutputStream fos = new FileOutputStream(f);
                    byte[] buf = new byte[4096];
                    int bytesRead;
                    while ((bytesRead = is.read(buf)) != -1) {
                        fos.write(buf, 0, bytesRead);
                    }
                    fos.close();
                    AttachItem att = new AttachItem(url, urlmd5);
                    listAttach.add(att);
                } catch (Exception e) {
                    continue;
                }
            }
            
            MimeMessage message = new MimeMessage(mailSession);
            message.setSubject(subjectMail, "utf-8");
            
            message.setContent(multipart);
            int cout = 0;
            String[] tempd = listInfoTo.split(",");
            if (listInfoTo != "") {
                for (int i = 0; i < tempd.length; i++) {
                    if (tempd[i] != "" && tempd[i].contains("@")) {
                        cout++;
                        message.addRecipient(Message.RecipientType.TO, new InternetAddress(tempd[i].trim()));
                    }
                    
                }
            }
            
            
            transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
            System.out.append("---------------2\n");

            // senmail CC to list 
            Address[] addr = null;
            if (listInfoTo != "") {
                addr = new Address[cout];
            }
            
            if (listInfoTo != "") {
                for (int i = 0; i < cout; i++) {
                    addr[i] = new InternetAddress(tempd[i]);
                }
            }
            MimeBodyPart textCC = new MimeBodyPart();
            if (addr != null && addr.length > 0) {
                textCC.setContent(contentMail, "text/html; charset=utf-8");
                multipart.addBodyPart(textCC);
                transport.sendMessage(message, addr);
            }
            
            transport.close();

            // cc
            System.out.println("m575Inf.updateM575N(" + getLogin().getModule() + " , " + getLogin().getCompanyNo() + " , " + this.getFb050() + " , " + this.getPm575() + " , " + 1 + " , " + subjectMail + " , " + this.getMv577() + " , " + "contentMail" + " , " + this.getMv579() + " , " + Util.toSQLDate(new Date()) + " , " + 0 + " , " + null + " , " + "D" + " , " + mailsend + " , " + getLogin().getUserName());
            int roweffect = m575Inf.updateM575N(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), this.getPm575(), 1, subjectMail, this.getMv577(), contentMail, this.getMv579(), Util.toSQLDate(new Date()), 0, null, "D", mailsend, getFm575repo(), getLogin().getUserName());
            
            if (roweffect > 0 && listAttach != null) {
                for (AttachItem attach : listAttach) {
                    try {
                        m650Store.updateM650(
                                0, loginSession.getLogin().getModule(), loginSession.getLogin().getCompanyNo(), 0, 0, null, 0,
                                "", attach.getUrl(), attach.getUrlmd5(),
                                0,
                                null, "M575", roweffect, 0, null, "MAIL", 7,
                                loginSession.getLogin().getUserName());
                    } catch (Exception e) {
                        continue;
                    }
                }
            }
            // save mail 
            if (roweffect > 0) {
                System.out.println("D:- m575Inf.updateM275( " + 0 + " , " + roweffect + " , " + idcus + " , " + "A" + " , " + "TO" + " , " + "D" + " , " + "S" + " , " + 0 + " , " + mailsend + " , " + getLogin().getUserName() + " )");
                int count = m575Inf.updateM275(0, roweffect, getFq100repo(), "A", "TO", "D", "S", 0, mailsend, getLogin().getUserName());
                System.out.println("D:- count: " + count);
            }
            String[] tempdcc = listInfo.split(",");
            System.out.println("listInfo: "+ listInfo);
            if (listInfo != "") {
                for (int i = 0; i < tempdcc.length; i++) {
                    if (!tempdcc[i].equals("")&& tempdcc[i].contains("@")) {
                        sendMailBcc(tempd[i].trim(), subjectMail, content, files);
                    }
                    
                }
            }
//                for (MailItem item : listMail) {
//                    if (item.getEmailAddress() != null && item.getEmailAddress() != "" && item.getEmailAddress().contains("@")) {
//
//                        String content = "";
//                        content = item.getSex() + ": " + item.getName() + "\n" + contentMail;
//                        sendMailBcc(item.getIditem(), item.getEmailAddress(), subjectMail, content, files, roweffect);
//                    }
//
//                }
            //end cc     

            chkMessS = true;
            files.clear();
        } catch (Exception e) {
            System.out.println("--D: Error from sendmail: " + e.getMessage());
            chkMess = true;
        }
    }

    public void sendMailBcc(String email, String subject, String content, ArrayList<File> files) {
        try {
            System.out.println("D:- mailsend id: " + mailsendId);
            if (getCheckN850()) {
                getM250ReviceById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            } else {
                getQ000SendById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            }
            Properties props = new Properties();
            
            props.put("mail.transport.protocol", "smtps");
            props.put("mail.smtp.host", SMTP_HOST_NAME);
            props.put("mail.smtps.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtps.from", "kakaka@machine");
            
            Session mailSession = Session.getInstance(props);
            mailSession.setDebug(true);
            Transport transport = mailSession.getTransport();
            System.out.append("---------------1\n");
            
            MimeMessage message = new MimeMessage(mailSession);
            message.setSubject(subject, "utf-8");
            
            MimeMultipart multipart = new MimeMultipart("mixed");
            
            for (int i = 0; i < files.size(); i++) {
                MimeBodyPart messageBodyPart1 = new MimeBodyPart();
                messageBodyPart1.attachFile(files.get(i).getPath());
                multipart.addBodyPart(messageBodyPart1);
            }
            message.setContent(multipart);           
            message.addRecipient(Message.RecipientType.CC, new InternetAddress(email));
            
            transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
            System.out.append("---------------2\n");
            
            MimeBodyPart textMBCC = new MimeBodyPart();
            textMBCC.setContent(content, "text/html; charset=utf-8");
            multipart.addBodyPart(textMBCC);
            Address[] st = new Address[1];
            st[0] = new InternetAddress(email);
            transport.sendMessage(message, st);
            
            transport.close();           
            
            
        } catch (Exception e) {
            System.out.println("--D: Error from sendmailREFO: " + e.getMessage());
            chkMess = true;
        }
    }
    
    public void sendMailBcc(int idcus, String email, String subject, String content, ArrayList<File> files, int roweffect) {
        try {
            System.out.println("D:- mailsend id: " + mailsendId);
            if (getCheckN850()) {
                getM250ReviceById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            } else {
                getQ000SendById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            }
            Properties props = new Properties();
            
            props.put("mail.transport.protocol", "smtps");
            props.put("mail.smtp.host", SMTP_HOST_NAME);
            props.put("mail.smtps.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtps.from", "kakaka@machine");
            
            Session mailSession = Session.getInstance(props);
            mailSession.setDebug(true);
            Transport transport = mailSession.getTransport();
            System.out.append("---------------1\n");
            
            MimeMessage message = new MimeMessage(mailSession);
            message.setSubject(subject, "utf-8");
            
            MimeMultipart multipart = new MimeMultipart("mixed");
            
            for (int i = 0; i < files.size(); i++) {
                MimeBodyPart messageBodyPart1 = new MimeBodyPart();
                messageBodyPart1.attachFile(files.get(i).getPath());
                multipart.addBodyPart(messageBodyPart1);
            }
            message.setContent(multipart);           
            message.addRecipient(Message.RecipientType.CC, new InternetAddress(email));
            
            transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
            System.out.append("---------------2\n");
            
            MimeBodyPart textMBCC = new MimeBodyPart();
            textMBCC.setContent(content, "text/html; charset=utf-8");
            multipart.addBodyPart(textMBCC);
            Address[] st = new Address[1];
            st[0] = new InternetAddress(email);
            transport.sendMessage(message, st);
            
            transport.close();

            // save mail 
            if (roweffect > 0) {
                System.out.println("D:- m575Inf.updateM275( " + 0 + " , " + roweffect + " , " + idcus + " , " + "A" + " , " + "TO" + " , " + "D" + " , " + "S" + " , " + 0 + " , " + mailsend + " , " + getLogin().getUserName() + " )");
                int count = m575Inf.updateM275(0, roweffect, getFq100repo(), "A", "TO", "D", "S", 0, mailsend, getLogin().getUserName());
                System.out.println("D:- count: " + count);
            }
            
            
            
            
        } catch (Exception e) {
            System.out.println("--D: Error from sendmailBCC: " + e.getMessage());
            chkMess = true;
        }
    }
    
    public void sendMailBccYAHOO(int idcus, String email, String subject, String content, ArrayList<File> files, int roweffect) {
        try {
            System.out.println("D:- mailsend id: " + mailsendId);
            if (getCheckN850()) {
                getM250ReviceById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            } else {
                getQ000SendById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            }
            String host, port;
            Properties props = System.getProperties();
            Session l_session = null;
            host = "smtp.mail.yahoo.com";
            port = "587";
            
            props.put("mail.smtp.host", host);
            props.put("mail.smtp.auth", "true");
            props.put("mail.debug", "false");
            props.put("mail.smtp.port", port);
            props.put("mail.smtp.starttls.enable", "true");
            
            l_session = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                        
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
                        }
                    });
            
            l_session.setDebug(true); // Enable the debug mode

            MimeMessage message = new MimeMessage(l_session);
            String emailid = SMTP_AUTH_USER;
            message.setFrom(new InternetAddress(emailid));
            message.addRecipient(Message.RecipientType.CC, new InternetAddress(email));
            MimeMultipart multipart = new MimeMultipart("mixed");
            
            for (int i = 0; i < files.size(); i++) {
                MimeBodyPart messageBodyPart1 = new MimeBodyPart();
                messageBodyPart1.attachFile(files.get(i).getPath());
                multipart.addBodyPart(messageBodyPart1);
            }
            message.setContent(multipart);
            message.setSubject(subject, "utf-8");
            message.setContent(contentMail, "text/html; charset=utf-8");
            Transport.send(message);
            System.out.println("Message Sent");

            // save mail 
            if (roweffect > 0) {
                m575Inf.updateM275(roweffect, roweffect, getFq100repo(), "A", "TO", "D", "S", 0, mailsend, getLogin().getUserName());
            }
            
            
        } catch (Exception e) {
            System.out.println("--D: Error from sendmailBCC: " + e.getMessage());
            chkMess = true;
        }
    }
    
    public void sendEmailTo() {
        try {
            System.out.println("D:- mailsend id: " + mailsendId);
            if (getCheckN850()) {
                getM250ReviceById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            } else {
                getQ000SendById(mailsendId);
                System.out.println("D:- mailsend: " + mailsend);
                System.out.println("D:- mailsend pass: " + mailsendpass);
                SMTP_AUTH_USER = mailsend;//your email address
                SMTP_AUTH_PWD = mailsendpass;//your password
            }
            if (SMTP_AUTH_USER.contains("@yahoo.com") || SMTP_AUTH_USER.contains("@ymail.com")) {
                String host, port;
                Properties props = System.getProperties();
                Session l_session = null;
                host = "smtp.mail.yahoo.com";
                port = "587";
                
                props.put("mail.smtp.host", host);
                props.put("mail.smtp.auth", "true");
                props.put("mail.debug", "false");
                props.put("mail.smtp.port", port);
                
                l_session = Session.getInstance(props,
                        new javax.mail.Authenticator() {
                            
                            protected PasswordAuthentication getPasswordAuthentication() {
                                return new PasswordAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
                            }
                        });
                
                l_session.setDebug(true); // Enable the debug mode

                MimeMessage message = new MimeMessage(l_session);
                String emailid = SMTP_AUTH_USER;
                message.setFrom(new InternetAddress(emailid));
                int cout = 0;
                String[] tempd = emailcus.split(",");
                if (emailcus != "") {
                    for (int i = 0; i < tempd.length; i++) {
                        if (tempd[i] != "" && tempd[i].contains("@")) {
                            cout++;
                            message.addRecipient(Message.RecipientType.CC, new InternetAddress(tempd[i].trim()));
                        }
                        
                    }
                }

                // senmail CC to list 
                Address[] addr = null;
                if (emailcus != "") {
                    addr = new Address[cout];
                }
                
                if (emailcus != "") {
                    for (int i = 0; i < cout; i++) {
                        addr[i] = new InternetAddress(tempd[i]);
                    }
                }
                MimeMultipart multipart = new MimeMultipart("mixed");
                List<AttachItem> listAttach = new ArrayList<AttachItem>();
                for (int i = 0; i < files.size(); i++) {
                    MimeBodyPart messageBodyPart1 = new MimeBodyPart();
                    messageBodyPart1.attachFile(files.get(i).getPath());
                    multipart.addBodyPart(messageBodyPart1);
                    
                    try {
                        InputStream is = new FileInputStream(files.get(i));
                        // save attach in sever
                        String url = files.get(i).getName().replaceAll(" ", "");
                        String urlmd5 = Util.createGUID() + "_" + files.get(i).getName().replaceAll(" ", "");
                        File f = new File(ResourcesProvider.getUploadMail() + urlmd5);
                        FileOutputStream fos = new FileOutputStream(f);
                        byte[] buf = new byte[4096];
                        int bytesRead;
                        while ((bytesRead = is.read(buf)) != -1) {
                            fos.write(buf, 0, bytesRead);
                        }
                        fos.close();
                        AttachItem att = new AttachItem(url, urlmd5);
                        listAttach.add(att);
                    } catch (Exception e) {
                        continue;
                    }
                    
                }
                message.setContent(multipart);
                message.setSubject(subjectMail, "utf-8");
                message.setContent(contentMail, "text/html; charset=utf-8");
                Transport.send(message);
                System.out.println("Message Sent");
                //Object obj = SessionProvider.getSessionMapValue("inout");
                Object obj = "D";
                int roweffect = m575Inf.updateM575By(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), this.getPm575(), 1, subjectMail, this.getMv577(), contentMail, this.getMv579(), Util.toSQLDate(new Date()), 0, obj.toString(), mailsend, 0, getLogin().getUserName());
                if (roweffect > 0 && listAttach != null) {
                    for (AttachItem attach : listAttach) {
                        try {
                            m650Store.updateM650(
                                    0, loginSession.getLogin().getModule(), loginSession.getLogin().getCompanyNo(), 0, 0, null, 0,
                                    "", attach.getUrl(), attach.getUrlmd5(),
                                    0,
                                    null, "M575", roweffect, 0, null, "MAIL", 7,
                                    loginSession.getLogin().getUserName());
                        } catch (Exception e) {
                            continue;
                        }
                    }
                }
                // save mail 
                if (roweffect > 0) {
                    
                    m575Inf.updateM275(roweffect, roweffect, idcus, "A", "TO", obj.toString(), "S", 0, mailsend, getLogin().getUserName());
                    
                    
                }

//            showGlobalReport(true, getResourceString("senmailsuccessful"));
//            sendRedirect(getPageRequest()+".jsp");
                if (chkMess) {
                    chkMessS = false;
                } else {
                    chkMessS = true;
                }
                files.clear();
                
            } else {
                Properties props = new Properties();
                
                props.put("mail.transport.protocol", "smtps");
                props.put("mail.smtp.host", SMTP_HOST_NAME);
                props.put("mail.smtps.auth", "true");
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtps.from", "kakaka@machine");
                
                Session mailSession = Session.getInstance(props);
                mailSession.setDebug(true);
                Transport transport = mailSession.getTransport();
                System.out.append("---------------1\n");
                
                MimeMessage message = new MimeMessage(mailSession);
                message.setSubject(subjectMail, "utf-8");
                
                MimeMultipart multipart = new MimeMultipart("mixed");
                List<AttachItem> listAttach = new ArrayList<AttachItem>();
                for (int i = 0; i < files.size(); i++) {
                    MimeBodyPart messageBodyPart1 = new MimeBodyPart();
                    messageBodyPart1.attachFile(files.get(i).getPath());
                    multipart.addBodyPart(messageBodyPart1);
                    
                    try {
                        InputStream is = new FileInputStream(files.get(i));
                        // save attach in sever
                        String url = files.get(i).getName().replaceAll(" ", "");
                        String urlmd5 = Util.createGUID() + "_" + files.get(i).getName().replaceAll(" ", "");
                        File f = new File(ResourcesProvider.getUploadMail() + urlmd5);
                        FileOutputStream fos = new FileOutputStream(f);
                        byte[] buf = new byte[4096];
                        int bytesRead;
                        while ((bytesRead = is.read(buf)) != -1) {
                            fos.write(buf, 0, bytesRead);
                        }
                        fos.close();
                        AttachItem att = new AttachItem(url, urlmd5);
                        listAttach.add(att);
                    } catch (Exception e) {
                        continue;
                    }
                    
                }
                message.setContent(multipart);

                //message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailcus));
                int cout = 0;
                String[] tempd = emailcus.split(",");
                if (emailcus != "") {
                    for (int i = 0; i < tempd.length; i++) {
                        if (tempd[i] != "" && tempd[i].contains("@")) {
                            cout++;
                            message.addRecipient(Message.RecipientType.CC, new InternetAddress(tempd[i].trim()));
                        }
                        
                    }
                }
                
                
                transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
                System.out.append("---------------2\n");

                // senmail CC to list 
                Address[] addr = null;
                if (emailcus != "") {
                    addr = new Address[cout];
                }
                
                if (emailcus != "") {
                    for (int i = 0; i < cout; i++) {
                        addr[i] = new InternetAddress(tempd[i]);
                    }
                }

                ///transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
                //System.out.append("---------------2\n");

                MimeBodyPart textMBCC = new MimeBodyPart();
                textMBCC.setContent(contentMail, "text/html; charset=utf-8");
                multipart.addBodyPart(textMBCC);
                //Address[] st = new Address[1];
                //st[0] = new InternetAddress(emailcus);
                if (emailcus != null && emailcus != "" && emailcus.contains("@")) {
                    transport.sendMessage(message, addr);
                } else {
                    chkMess = true;
                }
                
                
                transport.close();
                int roweffect = m575Inf.updateM575By(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), this.getPm575(), 1, subjectMail, this.getMv577(), contentMail, this.getMv579(), Util.toSQLDate(new Date()), 0, "D", mailsend, 0, getLogin().getUserName());
                if (roweffect > 0 && listAttach != null) {
                    for (AttachItem attach : listAttach) {
                        try {
                            m650Store.updateM650(
                                    0, loginSession.getLogin().getModule(), loginSession.getLogin().getCompanyNo(), 0, 0, null, 0,
                                    "", attach.getUrl(), attach.getUrlmd5(),
                                    0,
                                    null, "M575", roweffect, 0, null, "MAIL", 7,
                                    loginSession.getLogin().getUserName());
                        } catch (Exception e) {
                            continue;
                        }
                    }
                }
                // save mail 
                if (roweffect > 0) {
                    
                    m575Inf.updateM275(0, roweffect, idcus, "A", "TO", "D", "S", 0, mailsend, getLogin().getUserName());
                }
//            showGlobalReport(true, getResourceString("senmailsuccessful"));
//            sendRedirect(getPageRequest()+".jsp");
                if (chkMess) {
                    chkMessS = false;
                } else {
                    chkMessS = true;
                }
                files.clear();
            }
            
        } catch (Exception e) {
            System.out.println("--D: Error from sendmailTo: " + e.getMessage());
            chkMess = true;
//            showGlobalReport(true, getResourceString("senmailfail"));
//            sendRedirect(getPageRequest()+".jsp");
        }
    }
    
    public List<SelectItem> getSelectItemB050() {
        return comboxUtil.getListCombB050();
    }
    
    public List<SelectItem> getSelectItemQ100() {
        try {
            return comboxUtil.getListCombQ100();
        } catch (Exception ex) {
            return null;
        }
    }
    
    public List<M575> getListM275(String mv276, int pnFM575) {
        
        if (getLogin() != null) {
            int idx = getLogin().getId();
            System.out.println("list--->" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFb050() + "," + idx + "," + pnFM575 + " , " + this.getFm525() + "," + mv276 + "," + "I" + "," + getLogin().getUserName());
            try {
                List<M575> listM275 = m575Store.getListTabM275(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), idx, pnFM575, "A", mv276, "I", mailsend, 0, 10000, 0, 0, getLogin().getUserName());
                return listM275;
            } catch (Exception ex) {
                System.out.println("D: -- Error from getListM275: " + ex.getMessage());
                return new ArrayList<M575>();
            }
        } else {
            System.out.println("D: -- Error from getListM275: ");
            sendRedirect("login.jsp");
            return new ArrayList<M575>();
        }
        
    }

//    public List<M575> getListM275(String mv276, int pnFM575, String fm525) {
//
//        if (getLogin() != null) {
//            int idx = getLogin().getId();
//            System.out.println("list--->" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFb050() + "," + idx + "," + pnFM575 + " , " + this.getFm525() + "," + mv276 + "," + "I" + "," + getLogin().getUserName());
//            try {
//                List<M575> listM275TO = new ArrayList<M575>();
//                listM275TO = m575Store.getListTabM275D(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), idx, pnFM575, this.getFm525(), "TO", "I", getLogin().getUserName());
//                if (listM275TO != null) {
//                    List<M575> listM275FROM = new ArrayList<M575>();
//                    listM275FROM = m575Store.getListTabM275D(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), idx, pnFM575, this.getFm525(), "FROM", "I", getLogin().getUserName());
//                    for (M575 m575 : listM275FROM) {
//                        listM275TO.add(m575);
//                    }
//                }
//                return listM275TO;
//            } catch (Exception ex) {
//                System.out.println("D: -- Error from getListM275: " + ex.getMessage());
//                return new ArrayList<M575>();
//            }
//        } else {
//            System.out.println("D: -- Error from getListM275: ");
//            sendRedirect("login.jsp");
//            return new ArrayList<M575>();
//        }
//
//    }
    public List<M575> getListM275Ex(String mv276, int pnFM575) {
        int idx = getLogin().getId();
        if (getLogin() != null) {
            System.out.println("listabc--->" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFb050() + "," + idx + "," + pnFM575 + " , " + this.getFm525() + "," + mv276 + "," + "E" + "," + getLogin().getUserName());
            try {
                List<M575> listM275 = m575Store.getListTabM275(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), idx, pnFM575, this.getFm525(), mv276, "E", mailsend, 0, 10000, 0, 0, getLogin().getUserName());
                return listM275;
            } catch (Exception ex) {
                System.out.println("D: -- Error from getListM275: " + ex.getMessage());
                return new ArrayList<M575>();
            }
        } else {
            System.out.println("D: -- Error from getListM275: ");
            sendRedirect("login.jsp");
            return new ArrayList<M575>();
        }
        
    }

//    public void saveM575() {
//        int roweffect = 0;
//        try {
//            System.out.println("update--" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFb050() + "," + this.getPm575() + "," + 1 + "," + this.getMv576() + "," + this.getMv577() + "," + this.getMv578() + "," + this.getMv579() + "," + Util.toSQLDate(new Date()) + "," + 0 + "," + getLogin().getUserName());
//            roweffect = m575Inf.updateM575By(getLogin().getModule(), getLogin().getCompanyNo(), this.getFb050(), this.getPm575(), 1, this.getMv576(), this.getMv577(), this.getMv578(), this.getMv579(), Util.toSQLDate(new Date()), 0, "I",mailsend, getLogin().getUserName());
//            System.out.println("---------row----------" + roweffect);
//            if (roweffect > 0) {
//                Iterator icMap = getMap().entrySet().iterator();
//                while (icMap.hasNext()) {
//                    Map.Entry mapEntry = (Map.Entry) icMap.next();
////                    m575Inf.updateM275(roweffect, roweffect, Integer.parseInt(mapEntry.getKey().toString()), "A", "TO", "I", "S", null, getLogin().getUserName());
//                     m575Inf.updateM275(roweffect, roweffect,  "A", "TO", "I", "S", 0,mailsend, getLogin().getUserName());
//                }
//            }
//
//            reload = "<script type='text/javascript'>self.parent.tb_remove()</script>";
//            listToFromMail = getListM275("TO", 0);
//            map.clear();
//            checksendmail = true;
//
//
//
//        } catch (Exception ex) {
//            checksendmail = false;
//            showGlobalReport(true, getResourceString("datasuccessfail"));
//            sendRedirect("mail.jsp");
//        }
//
//
//    }
    public List<M575> getListToFromMail() {
        if (listToFromMail == null) {
            System.out.println("D:- call list !");
            listToFromMail = getListM275(mv276, 0);
            mailBox = "HỘP THƯ ĐẾN";
        }
        
        
        return listToFromMail;
    }
    
    public void actionListenner(ActionEvent evt) {
        System.out.println("actionlister is called !");
        String come_person = "";
        Iterator ic = comboxUtil.getListCombQ100().iterator();
        if (getFq100() == -1) {
            while (ic.hasNext()) {
                SelectItem item = (SelectItem) ic.next();
                getMap().put(Integer.parseInt(item.getValue().toString()), item.getLabel());
            }
        } else {
//            map.clear();

            while (ic.hasNext()) {
                SelectItem item = (SelectItem) ic.next();
                
                if (this.getFq100() == Integer.parseInt(item.getValue().toString())) {
                    System.out.println("---------m851----------" + item.getValue() + "----------" + item.getLabel());
                    System.out.println("D:- Lay nhan vien: " + item.getLabel());
                    getMap().put(this.getFq100(), item.getLabel());
                }
            }
        }
        
        listSendMail = new ArrayList(map.entrySet());
        if (listSendMail != null) {
            stylefrommail = "block";
        } else {
            stylefrommail = "none";
        }
        Iterator icMap = getMap().entrySet().iterator();
        while (icMap.hasNext()) {
            Map.Entry mapEntry = (Map.Entry) icMap.next();
            come_person += mapEntry.getValue();
            come_person += ",";
            System.out.println("--vvvvvvvvvvvvvvvvvvv--" + come_person + "-----------vkey--" + mapEntry.getKey());
            
        }
        //setMv576(come_person);
        System.out.println("SL map: " + map.size());
        SessionProvider.putSession("mapEmail", map);
        
        
    }

    //cau hinh mail gmail - yahoo
//    public Store storeGmailYahoo(String userMailYahoo, String passwordMailYahoo) {
//        Session session = null;
//        Store store = null;
//        String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//        Properties pop3Props = new Properties();
//        pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
//        pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
//        pop3Props.setProperty("mail.pop3.port", "995");
//        pop3Props.setProperty("mail.pop3.socketFactory.port", "995");
//        URLName url = new URLName("pop3", "pop.gmail.com", 995, "",
//                userMailYahoo, passwordMailYahoo);
//
//        session = Session.getInstance(pop3Props, null);
//        store = new POP3SSLStore(session, url);
//        try {
//            return store;
//        } catch (Exception ex) {
//            System.out.println("-------" + ex.getMessage());
//            return null;
//        }
//    }
//
//    public void check() {
//
//        try {
//
//            GmailUtilities gmail = new GmailUtilities();
//            gmail.setUserPass(" ", "");
//            gmail.connect();
//            gmail.openFolder("INBOX");
//
//            int totalMessages = gmail.getMessageCount();
//            int newMessages = gmail.getNewMessageCount();
//
//            System.out.println("Total messages = " + totalMessages);
//            System.out.println("New messages = " + newMessages);
//            System.out.println("-------------------------------");
//
//            //gmail.printAllMessageEnvelopes();
//            gmail.printAllMessages();
//
//        } catch (Exception e) {
//            System.out.println("D:--Eror from getMail from Gmail: " + e.getMessage());
//            e.printStackTrace();
//            System.exit(-1);
//        }
//    }
//    public void getListItemMailCcheck() throws IOException, MessagingException {
//        Properties props = new Properties();
//
//        props.put("mail.transport.protocol", "smtps");
//        props.put("mail.smtp.host", SMTP_HOST_NAME);
//        props.put("mail.smtps.auth", "true");
//        props.put("mail.smtp.starttls.enable", "true");
//        props.put("mail.smtps.from", "kakaka@machine");
//        props.setProperty("mail.store.protocol", "imaps");
//        props.setProperty("mail.imap.host", "imap.gmail.com");
//        props.setProperty("mail.imap.port", "993");
//        props.setProperty("mail.imap.connectiontimeout", "5000");
//        props.setProperty("mail.imap.timeout", "5000");
//        try {
//            Session session = Session.getDefaultInstance(props, null);
//            Store store = session.getStore("imaps");
//            store.connect("imap.gmail.com", "", "");
//            System.out.println(store);
//
//            Folder inbox = store.getFolder("Inbox");
//            inbox.open(Folder.READ_ONLY);
//            Message messages[] = inbox.getMessages();
//            System.out.println("D:--------------------------inbox------------------------");
//            for (Message message : messages) {
////
//                System.out.println("SentDate : " + message.getSentDate());
//                String from = message.getFrom()[0].toString();
//                System.out.println("From : " + from);
//                System.out.println("Subject : " + message.getSubject());
//                System.out.println("D:--" + message);
//            }
//        } catch (NoSuchProviderException e) {
//            e.printStackTrace();
//            System.exit(1);
//        } catch (MessagingException e) {
//            e.printStackTrace();
//            System.exit(2);
//        }
//    }
    public List<ItemMail> getListItemMailCcheck() throws IOException, MessagingException {
        System.out.println("-----------re mail -------------------");
        
        if (listitem != null && listitem.size() > 0) {
            Session session = null;
            Store store = null;
            String username, password;
            
            String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
            
            Properties pop3Props = new Properties();
            
            pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
            pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
            pop3Props.setProperty("mail.pop3.port", "995");
            pop3Props.setProperty("mail.pop3.socketFactory.port", "995");
            
            URLName url = new URLName("pop3", "pop.gmail.com", 995, "",
                    "saotitan.sao@gmail.com", "saotitan2011");
            
            session = Session.getInstance(pop3Props, null);
            store = new POP3SSLStore(session, url);
            try {
                store.connect();
                
            } catch (Exception ex) {
                System.out.println("-------" + ex.getMessage());
            }
            
            
            
            Folder folder = store.getFolder("inbox");

            // Open the Folder.
            folder.open(Folder.READ_ONLY);
            
            Message[] message = folder.getMessages();

            // Display message.
            for (int i = 0; i < message.length; i++) {
                
                System.out.println("------------ Message " + (i + 1) + " ------------");
                
                System.out.println("SentDate : " + message[i].getSentDate());
                String from = message[i].getFrom()[0].toString();
                ItemMail item = new ItemMail();
                item.setFromMail(from);
                listitem.add(item);
                SessionProvider.setSessionMapValue("listitem", listitem);
                System.out.println("From : " + from);
                System.out.println("Subject : " + message[i].getSubject());
                System.out.print("Message : ");

//  InputStream stream = message[i].getInputStream();
//  while (stream.available() != 0) {
//  System.out.print((char) stream.read());
//  }
//  System.out.println();
            }
            
            folder.close(true);
            store.close();
        }
        return listitem;
    }

    /**
     * @return the fb050
     */
    public int getFb050() {
        return fb050;
    }

    /**
     * @param fb050 the fb050 to set
     */
    public void setFb050(int fb050) {
        this.fb050 = fb050;
    }

    /**
     * @return the m575Inf
     */
    public M575Inf getM575Inf() {
        return m575Inf;
    }

    /**
     * @param m575Inf the m575Inf to set
     */
    public void setM575Inf(M575Inf m575Inf) {
        this.m575Inf = m575Inf;
    }

    /**
     * @return the pm575
     */
    public int getPm575() {
        return pm575;
    }

    /**
     * @param pm575 the pm575 to set
     */
    public void setPm575(int pm575) {
        this.pm575 = pm575;
    }

    /**
     * @return the ff150
     */
    public int getFf150() {
        return ff150;
    }

    /**
     * @param ff150 the ff150 to set
     */
    public void setFf150(int ff150) {
        this.ff150 = ff150;
    }

    /**
     * @return the mv576
     */
    public String getMv576() {
        return mv576;
    }

    /**
     * @param mv576 the mv576 to set
     */
    public void setMv576(String mv576) {
        this.mv576 = mv576;
    }

    /**
     * @return the mv577
     */
    public String getMv577() {
        if (SessionProvider.getSessionMapValue("mv577repo") != null) {
            mv577 = SessionProvider.getSessionMapValue("mv577repo").toString();
        }
        return mv577;
    }

    /**
     * @param mv577 the mv577 to set
     */
    public void setMv577(String mv577) {
        this.mv577 = mv577;
    }

    /**
     * @return the mv578
     */
    public String getMv578() {
        return mv578;
    }

    /**
     * @param mv578 the mv578 to set
     */
    public void setMv578(String mv578) {
        this.mv578 = mv578;
    }

    /**
     * @return the mv579
     */
    public String getMv579() {
        return mv579;
    }

    /**
     * @param mv579 the mv579 to set
     */
    public void setMv579(String mv579) {
        this.mv579 = mv579;
    }

    /**
     * @return the md580
     */
    public Date getMd580() {
        return md580;
    }

    /**
     * @param md580 the md580 to set
     */
    public void setMd580(Date md580) {
        this.md580 = md580;
    }

    /**
     * @return the mn581
     */
    public int getMn581() {
        return mn581;
    }

    /**
     * @param mn581 the mn581 to set
     */
    public void setMn581(int mn581) {
        this.mn581 = mn581;
    }

    /**
     * @return the fh000
     */
    public int getFh000() {
        return fh000;
    }

    /**
     * @param fh000 the fh000 to set
     */
    public void setFh000(int fh000) {
        this.fh000 = fh000;
    }

    /**
     * @return the fh200
     */
    public int getFh200() {
        return fh200;
    }

    /**
     * @param fh200 the fh200 to set
     */
    public void setFh200(int fh200) {
        this.fh200 = fh200;
    }

    /**
     * @return the reload
     */
    public String getReload() {
        return reload;
    }

    /**
     * @param reload the reload to set
     */
    public void setReload(String reload) {
        this.reload = reload;
    }

    /**
     * @return the intreload
     */
    public int getIntreload() {
        return intreload;
    }

    /**
     * @param intreload the intreload to set
     */
    public void setIntreload(int intreload) {
        this.intreload = intreload;
    }

    /**
     * @return the map
     */
    public Map<Integer, String> getMap() {
        Object obj = SessionProvider.getSessionMapValue("mapEmail");
        if (obj != null) {
            map = (Map<Integer, String>) obj;
        }
        return map;
    }

    /**
     * @param map the map to set
     */
    public void setMap(Map<Integer, String> map) {
        this.map = map;
    }

    /**
     * @return the listSendMail
     */
    public List<Map.Entry<Integer, String>> getListSendMail() {
        return listSendMail;
    }

    /**
     * @param listSendMail the listSendMail to set
     */
    public void setListSendMail(List<Map.Entry<Integer, String>> listSendMail) {
        this.listSendMail = listSendMail;
    }

    /**
     * @return the fq100
     */
    public int getFq100() {
        return fq100;
    }

    /**
     * @param fq100 the fq100 to set
     */
    public void setFq100(int fq100) {
        this.fq100 = fq100;
    }

    /**
     * @return the fm525
     */
    public String getFm525() {
        return fm525;
    }

    /**
     * @param fm525 the fm525 to set
     */
    public void setFm525(String fm525) {
        this.fm525 = fm525;
    }

    /**
     * @return the mv276
     */
    public String getMv276() {
        return mv276;
    }

    /**
     * @param mv276 the mv276 to set
     */
    public void setMv276(String mv276) {
        this.mv276 = mv276;
    }

    /**
     * @return the mv277
     */
    public String getMv277() {
        return mv277;
    }

    /**
     * @param mv277 the mv277 to set
     */
    public void setMv277(String mv277) {
        this.mv277 = mv277;
    }

    /**
     * @return the listToFromMail
     */
    /**
     * @param listToFromMail the listToFromMail to set
     */
    public void setListToFromMail(List<M575> listToFromMail) {
        this.listToFromMail = listToFromMail;
    }

    /**
     * @return the hoten
     */
    public String getHoten() {
        return hoten;
    }

    /**
     * @param hoten the hoten to set
     */
    public void setHoten(String hoten) {
        this.hoten = hoten;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the html
     */
    public String getHtml() {
        return html;
    }

    /**
     * @param html the html to set
     */
    public void setHtml(String html) {
        this.html = html;
    }

    /**
     * @return the text
     */
    public String getText() {
        return text;
    }

    /**
     * @param text the text to set
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * @return the sendtime
     */
    public Date getSendtime() {
        return sendtime;
    }

    /**
     * @param sendtime the sendtime to set
     */
    public void setSendtime(Date sendtime) {
        this.sendtime = sendtime;
    }

    /**
     * @return the renderMail
     */
    public int getRenderMail() {
        return renderMail;
    }

    /**
     * @param renderMail the renderMail to set
     */
    public void setRenderMail(int renderMail) {
        this.renderMail = renderMail;
    }

    /**
     * @return the loginGmailYahoo
     */
    public String getLoginGmailYahoo() {
        return loginGmailYahoo;
    }

    /**
     * @param loginGmailYahoo the loginGmailYahoo to set
     */
    public void setLoginGmailYahoo(String loginGmailYahoo) {
        this.loginGmailYahoo = loginGmailYahoo;
    }

    /**
     * @return the passwordGmailYahoo
     */
    public String getPasswordGmailYahoo() {
        return passwordGmailYahoo;
    }

    /**
     * @param passwordGmailYahoo the passwordGmailYahoo to set
     */
    public void setPasswordGmailYahoo(String passwordGmailYahoo) {
        this.passwordGmailYahoo = passwordGmailYahoo;
    }

    /**
     * @return the listItemMail
     */
    public List<ItemMail> getListItemMail() {
        
        return listItemMail;
    }

    /**
     * @param listItemMail the listItemMail to set
     */
    public void setListItemMail(List<ItemMail> listItemMail) {
        this.listItemMail = listItemMail;
    }

    /**
     * @return the fromMail
     */
    public String getFromMail() {
        return fromMail;
    }

    /**
     * @param fromMail the fromMail to set
     */
    public void setFromMail(String fromMail) {
        this.fromMail = fromMail;
    }

    /**
     * @return the toMail
     */
    public String getToMail() {
        return toMail;
    }

    /**
     * @param toMail the toMail to set
     */
    public void setToMail(String toMail) {
        this.toMail = toMail;
    }

    /**
     * @return the dateSend
     */
    public String getDateSend() {
        return dateSend;
    }

    /**
     * @param dateSend the dateSend to set
     */
    public void setDateSend(String dateSend) {
        this.dateSend = dateSend;
    }

    /**
     * @return the titleMail
     */
    public String getTitleMail() {
        return titleMail;
    }

    /**
     * @param titleMail the titleMail to set
     */
    public void setTitleMail(String titleMail) {
        this.titleMail = titleMail;
    }

    /**
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * @param content the content to set
     */
    public void setContent(String content) {
        this.content = content;
    }

    /**
     * @return the listitem
     */
    public List<ItemMail> getListitem() {
        listitem = (List<ItemMail>) SessionProvider.getSessionMapValue("listitem");
        return listitem;
    }

    /**
     * @param listitem the listitem to set
     */
    public void setListitem(List<ItemMail> listitem) {
        this.listitem = listitem;
    }

    /**
     * @return the colorchose
     */
    public String getColorchose() {
        return colorchose;
    }

    /**
     * @param colorchose the colorchose to set
     */
    public void setColorchose(String colorchose) {
        this.colorchose = colorchose;
    }

    /**
     * @return the stylefrommail
     */
    public String getStylefrommail() {
        return stylefrommail;
    }

    /**
     * @param stylefrommail the stylefrommail to set
     */
    public void setStylefrommail(String stylefrommail) {
        this.stylefrommail = stylefrommail;
    }

    /**
     * @return the subjectMail
     */
    public String getSubjectMail() {
        return subjectMail;
    }

    /**
     * @param subjectMail the subjectMail to set
     */
    public void setSubjectMail(String subjectMail) {
        this.subjectMail = subjectMail;
    }

    /**
     * @return the contentMail
     */
    public String getContentMail() {
        return contentMail;
    }

    /**
     * @param contentMail the contentMail to set
     */
    public void setContentMail(String contentMail) {
        this.contentMail = contentMail;
    }

    /**
     * @return the methodSend
     */
    public String getMethodSend() {
        return methodSend;
    }

    /**
     * @param methodSend the methodSend to set
     */
    public void setMethodSend(String methodSend) {
        this.methodSend = methodSend;
    }

    /**
     * @return the listInfo
     */
    public String getListInfo() {
        return listInfo;
    }

    /**
     * @param listInfo the listInfo to set
     */
    public void setListInfo(String listInfo) {
        this.listInfo = listInfo;
    }

    /**
     * @return the listMail
     */
    public List<MailItem> getListMail() {
        return listMail;
    }

    /**
     * @param listMail the listMail to set
     */
    public void setListMail(List<MailItem> listMail) {
        this.listMail = listMail;
    }

    /**
     * @return the listInfoTo
     */
    public String getListInfoTo() {
        return listInfoTo;
    }

    /**
     * @param listInfoTo the listInfoTo to set
     */
    public void setListInfoTo(String listInfoTo) {
        this.listInfoTo = listInfoTo;
    }

    /**
     * @return the s
     */
    public String getS() {
        return s;
    }

    /**
     * @param s the s to set
     */
    public void setS(String s) {
        this.s = s;
    }

    /**
     * @return the chkMess
     */
    public Boolean getChkMess() {
        return chkMess;
    }

    /**
     * @param chkMess the chkMess to set
     */
    public void setChkMess(Boolean chkMess) {
        this.chkMess = chkMess;
    }

    /**
     * @return the chkMessS
     */
    public Boolean getChkMessS() {
        return chkMessS;
    }

    /**
     * @param chkMessS the chkMessS to set
     */
    public void setChkMessS(Boolean chkMessS) {
        this.chkMessS = chkMessS;
    }

    /**
     * @return the filetemp
     */
    public String getFiletemp() {
        return filetemp;
    }

    /**
     * @param filetemp the filetemp to set
     */
    public void setFiletemp(String filetemp) {
        this.filetemp = filetemp;
    }

    /**
     * @return the idcus
     */
    public int getIdcus() {
        return idcus;
    }

    /**
     * @param idcus the idcus to set
     */
    public void setIdcus(int idcus) {
        this.idcus = idcus;
    }

    /**
     * @return the emailcus
     */
    public String getEmailcus() {
        return emailcus;
    }

    /**
     * @param emailcus the emailcus to set
     */
    public void setEmailcus(String emailcus) {
        this.emailcus = emailcus;
    }

    /**
     * @return the typecus
     */
    public String getTypecus() {
        return typecus;
    }

    /**
     * @param typecus the typecus to set
     */
    public void setTypecus(String typecus) {
        this.typecus = typecus;
    }

    /**
     * @return the senper
     */
    public Boolean getSenper() {
        return senper;
    }

    /**
     * @param senper the senper to set
     */
    public void setSenper(Boolean senper) {
        this.senper = senper;
    }

    /**
     * @return the pageRequest
     */
    public String getPageRequest() {
        return pageRequest;
    }

    /**
     * @param pageRequest the pageRequest to set
     */
    public void setPageRequest(String pageRequest) {
        this.pageRequest = pageRequest;
    }

    /**
     * @return the mailBox
     */
    public String getMailBox() {
        
        return mailBox;
    }

    /**
     * @param mailBox the mailBox to set
     */
    public void setMailBox(String mailBox) {
        this.mailBox = mailBox;
    }

    /**
     * @return the listToFromMailEx
     */
    public List<M575> getListToFromMailEx() {
        listToFromMailEx = getListM275Ex("FROM", 0);
        return listToFromMailEx;
    }

    /**
     * @param listToFromMailEx the listToFromMailEx to set
     */
    public void setListToFromMailEx(List<M575> listToFromMailEx) {
        this.listToFromMailEx = listToFromMailEx;
    }

    /**
     * @return the check
     */
    public String getCheck() {
        return check;
    }

    /**
     * @param check the check to set
     */
    public void setCheck(String check) {
        this.check = check;
    }

    /**
     * @return the checksendmail
     */
    public Boolean getChecksendmail() {
        return checksendmail;
    }

    /**
     * @param checksendmail the checksendmail to set
     */
    public void setChecksendmail(Boolean checksendmail) {
        this.checksendmail = checksendmail;
    }
    
    public void automail() {
        try {
            JobDetail job = new JobDetail();
            job.setName("dummyJobName");
            job.setJobClass(SchedulerJob.class);
            
            CronTrigger trigger = new CronTrigger();
            trigger.setName("dummyTriggerName");
            trigger.setCronExpression("0/30 * * * * ?");

            //schedule it
            Scheduler scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();
            scheduler.scheduleJob(job, trigger);
            
        } catch (Exception e) {
            System.out.println("D:- Error from automail: " + e.getMessage());
        }
    }

    /**
     * @return the sttTitle
     */
    public String getSttTitle() {
        System.out.println("D:- sttTitle: " + sttTitle);
        return sttTitle;
    }

    /**
     * @param sttTitle the sttTitle to set
     */
    public void setSttTitle(String sttTitle) {
        this.sttTitle = sttTitle;
    }

    /**
     * @return the listcomboM200
     */
    public List<SelectItem> getListcomboM200() {
        listcomboM200 = comboxUtil.getlistCombM200();
        return listcomboM200;
    }

    /**
     * @param listcomboM200 the listcomboM200 to set
     */
    public void setListcomboM200(List<SelectItem> listcomboM200) {
        this.listcomboM200 = listcomboM200;
    }

    /**
     * @return the valuemailtemp
     */
    public String getValuemailtemp() {
        
        return valuemailtemp;
    }

    /**
     * @param valuemailtemp the valuemailtemp to set
     */
    public void setValuemailtemp(String valuemailtemp) {
        this.valuemailtemp = valuemailtemp;
    }
    
    public void change4ldv(ActionEvent ac) {
        List<M200> list = m200Store.getListM200All(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getId(), getLogin().getUserName());
        if (list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getPm200() == getPm200()) {
                    this.contentMail = (list.get(i).getMv202());
                    break;
                }
            }
        }
//        System.out.println("D:- valuemailtemp : "+ valuemailtemp);
    }

    /**
     * @return the pm200
     */
    public int getPm200() {
        return pm200;
    }

    /**
     * @param pm200 the pm200 to set
     */
    public void setPm200(int pm200) {
        this.pm200 = pm200;
    }

    /**
     * @return the stephide
     */
    public int getStephide() {
        return stephide;
    }

    /**
     * @param stephide the stephide to set
     */
    public void setStephide(int stephide) {
        this.stephide = stephide;
    }

    /**
     * @return the timezone
     */
    public long getTimezone() {
        timezone = new Date().getTime();
        return timezone;
    }

    /**
     * @param timezone the timezone to set
     */
    public void setTimezone(long timezone) {
        this.timezone = timezone;
    }

    /**
     * @return the mailsend
     */
    public String getMailsend() {
        return mailsend;
    }

    /**
     * @param mailsend the mailsend to set
     */
    public void setMailsend(String mailsend) {
        this.mailsend = mailsend;
    }

    /**
     * @return the listcomboQ000
     */
    public List<SelectItem> getListcomboQ000() {
        try {
            listcomboQ000 = comboxUtil.getListComboQ000();
        } catch (Exception e) {
            System.out.println("D:- error from getListcomboQ000: " + e.getMessage());
        }
        return listcomboQ000;
    }

    /**
     * @param listcomboQ000 the listcomboQ000 to set
     */
    public void setListcomboQ000(List<SelectItem> listcomboQ000) {
        this.listcomboQ000 = listcomboQ000;
    }

    /**
     * @return the mailsendId
     */
    public int getMailsendId() {
        return mailsendId;
    }

    /**
     * @param mailsendId the mailsendId to set
     */
    public void setMailsendId(int mailsendId) {
        this.mailsendId = mailsendId;
    }

    /**
     * @return the mailsendpass
     */
    public String getMailsendpass() {
        return mailsendpass;
    }

    /**
     * @param mailsendpass the mailsendpass to set
     */
    public void setMailsendpass(String mailsendpass) {
        this.mailsendpass = mailsendpass;
    }

    /**
     * @return the listcomboM250
     */
    public List<SelectItem> getListcomboM250() {
        try {
            listcomboM250 = comboxUtil.getListComboM250();
        } catch (Exception e) {
            System.out.println("D:- error from listcomboM250: " + e.getMessage());
        }
        return listcomboM250;
    }

    /**
     * @param listcomboM250 the listcomboM250 to set
     */
    public void setListcomboM250(List<SelectItem> listcomboM250) {
        this.listcomboM250 = listcomboM250;
    }
    
    public Boolean getCheckN850() {
        if (SessionProvider.getSessionMapValue("checkN850") != null) {
            try {
                int n = Integer.parseInt(SessionProvider.getSessionMapValue("checkN850").toString().trim());
                if (n == 1) {
                    checkN850 = true;
                } else {
                    checkN850 = false;
                }
            } catch (Exception e) {
                checkN850 = false;
            }
            
        }
        return checkN850;
    }

    /**
     * @param checkN850 the checkN850 to set
     */
    public void setCheckN850(Boolean checkN850) {
        this.checkN850 = checkN850;
    }

    /**
     * @return the fm575repo
     */
    public int getFm575repo() {
        if (SessionProvider.getSessionMapValue("fm575repo") != null) {
            try {
                fm575repo = Integer.parseInt(SessionProvider.getSessionMapValue("fm575repo").toString());
            } catch (Exception e) {
                System.err.println("error from: getfm575repo: " + e.getMessage());
            }
        }
        return fm575repo;
    }

    /**
     * @param fm575repo the fm575repo to set
     */
    public void setFm575repo(int fm575repo) {
        this.fm575repo = fm575repo;
    }

    /**
     * @return the fm575list
     */
    public int getFm575list() {
        return fm575list;
    }

    /**
     * @param fm575list the fm575list to set
     */
    public void setFm575list(int fm575list) {
        this.fm575list = fm575list;
    }

    /**
     * @return the listmailrepo
     */
    public List<M575> getListmailrepo() {
        try {
            M575Store store = new M575Store();
            System.out.println("store.mcurpks_listoftabm275ref(" + getLogin().getModule() + " , " + getLogin().getCompanyNo() + " , " + fm575list + " , " + getLogin().getUserName());
            listmailrepo = store.mcurpks_listoftabm275ref(getLogin().getModule(), getLogin().getCompanyNo(), fm575list, getLogin().getUserName());
            if (listmailrepo != null) {
                System.out.println("listmailrepo.size(): " + listmailrepo.size());
            }
        } catch (Exception e) {
            listmailrepo = new ArrayList<M575>();
            System.err.println("D:- error from getListmailrepo:  " + e.getMessage());
        }
        return listmailrepo;
    }

    /**
     * @param listmailrepo the listmailrepo to set
     */
    public void setListmailrepo(List<M575> listmailrepo) {
        this.listmailrepo = listmailrepo;
    }

    /**
     * @return the fq100repo
     */
    public int getFq100repo() {
        if (SessionProvider.getSessionMapValue("fq100repo") != null) {
            try {
                fq100repo = Integer.parseInt(SessionProvider.getSessionMapValue("fq100repo").toString());
            } catch (Exception e) {
                System.err.println("error from: getfq100repo: " + e.getMessage());
            }
        }
        return fq100repo;
    }

    /**
     * @param fq100repo the fq100repo to set
     */
    public void setFq100repo(int fq100repo) {
        this.fq100repo = fq100repo;
    }
}
